home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 September
/
PCWorld_2008-09_cd.bin
/
v cisle
/
sadanastroju
/
bookmark_previews-0.6.5-fx.xpi
/
chrome
/
content
/
managerOverlay.js
< prev
next >
Wrap
Text File
|
2008-05-27
|
33KB
|
792 lines
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Bookmark Previews extension.
*
* The Initial Developer of the Original Code is
* John Marshall <JohnM555@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* John Marshall <JohnM555@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
if (!("Ci" in window)){
Ci = Components.interfaces;
Cc = Components.classes;
}
var ThumbView = null;
var PreviewImages = {
folder : {
url: "chrome://bookmarkpreviews/skin/folder.png",
image: null
},
nopreview : {
url: "chrome://bookmarkpreviews/skin/nopreview.png",
image: null
}
}
var BookmarksPreviewUtils = {
utils : null,
displayRoot : null,
location : null,
contentDeck : null,
selected : null,
dir : null,
bkmksTree : null,
placesTree : null,
_history : [],
_historyIndex : 0,
init : function(){
try{
//dump("init\n");
var self = BookmarksPreviewUtils;
BookmarksPreviewUtils.dir = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsIFile);
BookmarksPreviewUtils.dir.append("bookmarkpreviews");
if (!BookmarksPreviewUtils.dir.exists())
BookmarksPreviewUtils.dir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE,0777);
self.placesTree = document.getElementById("bookmark-folders-view");
var folderWidth = self.placesTree.getAttribute("width");
/* since some lovely person decided, 'Hey, we don't need to include ids
in order to make it easier for extension developers to overlay the
bookmarks manager' these elements need to be added & positioned with
javascript. Yay! */
var vbox = document.createElement("vbox");
vbox.setAttribute("id","defaultView");
self.bkmksTree = document.getElementById("bookmarks-view");
var bkmksWidth = self.bkmksTree.boxObject.width;//document.documentElement.boxObject.width - self.placesTree.width;//self.bkmksTree.boxObject.width
var container = document.getElementById("albumview-container");
container = container.parentNode.removeChild(container);
vbox.appendChild(container);
var splitter = document.createElement("splitter");
var grippy = document.createElement("grippy");
splitter.appendChild(grippy);
splitter.setAttribute("id","albumview-splitter");
splitter.setAttribute("oncommand","BookmarksPreviewUtils.onResize(event);");
vbox.appendChild(splitter);
var deck = document.createElement("deck");
//var deck = document.createElement("vbox");
deck.setAttribute("id","contentDeck");
deck.setAttribute("persist","width");
deck.setAttribute("flex","4");
deck.appendChild(vbox);
self.bkmksTree.parentNode.insertBefore(deck,self.bkmksTree);
/* Since xbl kills babies(bug 50349) the destructor isn't called when this
is removed, although the constructor is called when it is re-added. That
means the transaction listener and other observers get added twice.
Not good.... So remove it before we (re)move the element.
This prevents leaking.
*/
self._bkmksTreeDestructor(self.bkmksTree);
self.bkmksTree.parentNode.removeChild(self.bkmksTree);
vbox.appendChild(self.bkmksTree);
self.bkmksTree.treeBuilder.addObserver(BookmarksPreviewUtils);
//bmFolderView.treeBuilder.addObserver(BookmarksPreviewUtils);
/* Listen to when ref changes instead of the left tree's select
observer because we also want to be notified when a search has
been performed
*/
self.bkmksTree.addEventListener("DOMAttrModified",self.refModified,false);
/* set the folder tree back to its original size. After we remove the bkmks tree
(so we can insert it into the deck) the folders tree expands because its flex is 1.*/
//setTimeout(function(){
//self.placesTree.setAttribute("width",folderWidth);
//deck.setAttribute("width",bkmksWidth);
//},11);
/* Once again, because this window was designed to be soo extensible, I need to
add any new menu items in through here instead of with a nice, quick, xul overlay */
var export_menuitem = document.getElementsByAttribute("command","cmd_bm_export")[0];
var create_menuitem = document.getElementById("create_previews");
export_menuitem.parentNode.insertBefore(create_menuitem,export_menuitem.nextSibling);
/* create new menu items in the view menu */
var nextElement = curElement = document.getElementById("view-separator");
var insertbefore = document.getElementById("fill-after-this-node");
var viewMenu = insertbefore.parentNode;
var addItems = true;
while(addItems){
nextElement = curElement.nextSibling;
addItems = curElement.id!="thumbsSize";
viewMenu.insertBefore(curElement,insertbefore);
curElement = nextElement;
}
/* Insert thumnail view in the correct spot */
//ThumbView = document.getElementById("thumbnailView");
//ThumbView = ThumbView.parentNode.removeChild(ThumbView);
ThumbView = document.createElement("thumbnailview");
ThumbView.setAttribute("id","thumbnailView");
ThumbView = deck.appendChild(ThumbView);
//dump("thumbview: "+ThumbView+"\n");
splitter = document.getElementById("bookmark-views-splitter");
splitter.setAttribute("oncommand","BookmarksPreviewUtils.onResize(event);");
const kPrefSvcContractID = "@mozilla.org/preferences-service;1";
const kPrefSvcIID = Components.interfaces.nsIPrefService;
var prefSvc = Components.classes[kPrefSvcContractID].getService(kPrefSvcIID);
var prefs = prefSvc.getBranch(null);
const kPrefBranchInternalIID = Components.interfaces.nsIPrefBranch2;
var bookmarksPrefsInternal = prefs.QueryInterface(kPrefBranchInternalIID);
bookmarksPrefsInternal.addObserver(self.sortChangedObserver.domain,
self.sortChangedObserver, false);
BookmarksPreviewUtils.contentDeck = deck;
var detailsMenu = document.getElementById("detailsViewMenu");
if (detailsMenu.getAttribute("checked"))
BookmarksPreviewUtils.onSelectView('details');
else{
var thumbsMenu = detailsMenu.nextSibling;
if (!thumbsMenu.getAttribute("checked"))
BookmarksPreviewUtils.onSelectView('details');
else
BookmarksPreviewUtils.onSelectView('thumbnails');
}
// Adding the transaction listener
var bkmkTxnSvc = Components.classes["@mozilla.org/bookmarks/transactionmanager;1"]
.getService(Components.interfaces.nsIBookmarkTransactionManager);
bkmkTxnSvc.transactionManager.AddListener(self);
BMDS.AddObserver(self);
window.addEventListener("resize",self.onResize,false);
/* Listen for when the previews get updated */
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(self, "bookmarkpreviews:preview-updated", false);
setTimeout(function(){
self.bkmksTree.focus();
self.bkmksTree.tree.view.selection.select(0);
},0);
}catch(e){Components.utils.reportError(e);}
},
_bkmksTreeDestructor : function(aBkmksTree){
var bkmkTxnSvc = Components.classes["@mozilla.org/bookmarks/transactionmanager;1"]
.getService(Components.interfaces.nsIBookmarkTransactionManager);
bkmkTxnSvc.transactionManager.RemoveListener(aBkmksTree.bookmarkTreeTransactionListener);
aBkmksTree.treeBuilder.removeObserver(aBkmksTree.builderObserver);
aBkmksTree.tree.controllers.removeController(aBkmksTree.controller);
// Unhook the sort change observer for this tree
const kPrefSvcContractID = "@mozilla.org/preferences-service;1";
const kPrefSvcIID = Components.interfaces.nsIPrefService;
var prefSvc = Components.classes[kPrefSvcContractID].getService(kPrefSvcIID);
var prefs = prefSvc.getBranch(null);
const kPrefBranchInternalIID = Components.interfaces.nsIPrefBranch2;
var bookmarksPrefsInternal = prefs.QueryInterface(kPrefBranchInternalIID);
bookmarksPrefsInternal.removeObserver(aBkmksTree.sortChangedObserver.domain,
aBkmksTree.sortChangedObserver);
},
uninit : function(){
var self = BookmarksPreviewUtils;
self.bkmksTree.treeBuilder.removeObserver(BookmarksPreviewUtils);
self.bkmksTree.removeEventListener("DOMAttrModified",self.refModified,false);
window.removeEventListener("resize",self.onResize,false);
// Unhook the sort change observer
const kPrefSvcContractID = "@mozilla.org/preferences-service;1";
const kPrefSvcIID = Components.interfaces.nsIPrefService;
var prefSvc = Components.classes[kPrefSvcContractID].getService(kPrefSvcIID);
var prefs = prefSvc.getBranch(null);
const kPrefBranchInternalIID = Components.interfaces.nsIPrefBranch2;
var bookmarksPrefsInternal = prefs.QueryInterface(kPrefBranchInternalIID);
bookmarksPrefsInternal.removeObserver(self.sortChangedObserver.domain,
self.sortChangedObserver);
var bkmkTxnSvc = Components.classes["@mozilla.org/bookmarks/transactionmanager;1"]
.getService(Components.interfaces.nsIBookmarkTransactionManager);
bkmkTxnSvc.transactionManager.RemoveListener(self);
BMDS.RemoveObserver(self)
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(self, "bookmarkpreviews:preview-updated");
if (ThumbView.initiated)
ThumbView.uninit();
if (AlbumView.initiated)
AlbumView.uninit();
},
onResize : function(event){
BookmarksPreviewUtils.utils.onResize(event);
},
refModified : function(event){
if (event.attrName=="ref" && event.target == BookmarksPreviewUtils.bkmksTree
&& !BookmarksPreviewUtils.utils.updatedSelection){
//dump("ref modified\n");
BookmarksPreviewUtils.utils.refreshDisplay();
}
},
sortChangedObserver : {
domain: "browser.bookmarks.sort",
_isSorted : null,
/*
What were these people thinking? I must be missing something obvious
because apparently if the tree is unsorted(aka natural), the direction
is descending, when the tree is ascending, the direction is natural,
and when the tree is descending, the direction is ascending.
How does that make sense?!
So instead of logically check that the current direction is not "natural",
which most people in this context would take to mean unsorted, we need to
make sure the direction is not "descending". Duh.
*/
get isSorted(){
if (this._isSorted == null){
var prefSvc = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
var prefs = prefSvc.getBranch(this.domain+".");
this._isSorted = prefs.getCharPref("direction") != "descending";
}
return this._isSorted;
},
observe: function BMU_sortChangedObserver(aSubject, aTopic, aPrefName) {
if (aTopic != "nsPref:changed") return;
if (aPrefName.substr(0, this.domain.length) != this.domain) return;
//dump("sort changed\n");
var prefSvc = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
var prefs = prefSvc.getBranch(this.domain+".");
this._isSorted = prefs.getCharPref("direction") != "descending";
//dump("sort direction: "+prefs.getCharPref("direction")+"\n");
setTimeout(function(){
/* this is called before the tree ends up getting sorted, which we need because
we take the results directly from the tree's view. setTimeout fixes it.
*/
BookmarksPreviewUtils.utils.refreshDisplay(true);//.refreshSort();
},0);
}
},
onSelectView : function(type,event){
//dump("type: "+type+"\n");
var self = BookmarksPreviewUtils;
self.selected = type;
if (type=="details"){
if (!event || self.contentDeck.selectedIndex!=0){
self.contentDeck.selectedIndex=0;
if (ThumbViewUtils.initiated){
ThumbViewUtils.uninit();
}
AlbumViewUtils.initDisplay();
}
} else if (type=="thumbnails"){
if (!event || self.contentDeck.selectedIndex!=1){
self.contentDeck.selectedIndex=1;
if (AlbumView.initiated){
AlbumView.uninit();
ThumbViewUtils.initDisplay();
}
else{/* first load, give time for the contents to get set up */
setTimeout(function(){ThumbViewUtils.initDisplay();},0);
}
}
}
},
getViewRoot : function(aCurIndex, aRootIndex){
var root;
var curIndex = BookmarksPreviewUtils.bkmksTree.currentIndex;
var rootIndex = -1;
if (curIndex>-1 && BookmarksPreviewUtils.bkmksTree.tree.view.isContainer(curIndex))
rootIndex = curIndex;
else if (curIndex>-1)
rootIndex = BookmarksPreviewUtils.bkmksTree.tree.view.getParentIndex(curIndex);;
if (rootIndex>-1)
root = BookmarksPreviewUtils.bkmksTree.getRowResource(rootIndex);
else{
root = BookmarksPreviewUtils.bkmksTree.getRootResource();
}
if (BookmarksPreviewUtils.displayRoot != root){
BookmarksPreviewUtils.addToBackHistory(root,"utils");
BookmarksPreviewUtils.displayRoot = root;
}
if (aCurIndex)
aCurIndex.value = curIndex;
if (aRootIndex)
aRootIndex.value = rootIndex;
return root;
},
getBookmarkImages : function(bkmks,folder){
if (!folder)
folder = BookmarksPreviewUtils.getViewRoot();
var self = BookmarksPreviewUtils;
var idx = self.bkmksTree.treeBuilder.getIndexOfResource(folder);
var view = self.bkmksTree.tree.view;
var urlCol = self.bkmksTree.tree.columns.getNamedColumn("URL");
var nameCol = self.bkmksTree.tree.columns.getNamedColumn("Name");
var rowCount = view.rowCount;
if (rowCount>0){
var isOpen = idx==-1 || view.isContainerOpen(idx);
if (!isOpen) {
view.toggleOpenState(idx);
rowCount = view.rowCount;
}
var level = view.getLevel(idx+1);
var containerLevel = idx>-1?view.getLevel(idx):-1;
if (level > containerLevel){
for (var i = idx+1; i<rowCount; i++){
var rowLevel = view.getLevel(i);
if (rowLevel==level){
var resource = self.bkmksTree.getRowResource(i);
if (resource instanceof Components.interfaces.nsIRDFResource){
var aType = BookmarksUtils.resolveType(resource);
if (aType!="BookmarkSeparator"){
var url = null;
if (!view.isContainer(i))
url = view.getCellText(i,urlCol);
var name = view.getCellText(i,nameCol);
var image = BookmarksPreviewUtils._getResourceImage(aType,url);
bkmks.push({image: image,
caption: name && name.length>0?name:url,
url: url,
node: resource});
}
}
}
else if (rowLevel<level){
break;
}
}
}
if (!isOpen) view.toggleOpenState(idx);
}
},
_getResourceImage : function(aType,aURL){
var folderImage = "chrome://bookmarkpreviews/skin/folder.png";
if (aType == "Livemark" || aType == "Folder" || aType=="PersonalToolbarFolder"){
return folderImage;
}
return this.getImageForURL(aURL);
},
getImageForURL : function(aURL){
var nopreview = "chrome://bookmarkpreviews/skin/nopreview.png";
if (aURL){
var file = PreviewServiceUtils.getPreviewFile(aURL,this.dir);
if (file.exists() && file.isFile()){
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var uri = ios.newFileURI(file);
if (uri)
return uri.spec;
}
}
return nopreview;
},
addToBackHistory : function(resource,from){
if (!this._history.some(function(ele,idx){
return ele.Value == resource.Value;
})){
this._history.splice(0,this._historyIndex==0?0:this._historyIndex,resource);
this._historyIndex = 0;
}
this.updateNavigationStates();
},
back : function(event){
this.navigateHistory(1);
},
forward : function(event){
this.navigateHistory(-1);
},
navigateHistory : function(direction){
var location = this.getViewRoot();
this._historyIndex+=direction;
var historyEntry = this._history[this._historyIndex];
BookmarksPreviewUtils.utils.updatedSelection = true;
//var parent = BMDS.getParent(resource);
if (historyEntry.Value=="NC:BookmarksTopRoot"){
this.bkmksTree.tree.ref=historyEntry.Value;
this.bkmksTree.tree.view.selection.clearSelection();
this.bkmksTree.tree.view.selection.currentIndex=-1;
}
else{
this.placesTree.tree.view.selection.clearSelection();
this.placesTree.selectResource(historyEntry);
var parent = BMDS.getParent(historyEntry);
this.bkmksTree.tree.ref=parent.Value;
this.bkmksTree.tree.view.selection.clearSelection();
this.bkmksTree.selectResource(historyEntry);
}
BookmarksPreviewUtils.utils.updatedSelection = false;
this.placesTree.treeBoxObject.ensureRowIsVisible(
this.placesTree.treeBuilder.getIndexOfResource(historyEntry));
BookmarksPreviewUtils.utils.refreshDisplay();
this.updateNavigationStates();
},
updateNavigationStates : function(){
var backbutton = document.getElementById("back-button");
if (this._historyIndex==this._history.length-1 ){
backbutton.setAttribute("disabled","true");
}
else
backbutton.removeAttribute("disabled");
var forwardbutton = document.getElementById("forward-button");
if (this._historyIndex==0 ){
forwardbutton.setAttribute("disabled","true");
}
else
forwardbutton.removeAttribute("disabled");
},
canDrop : function(index, orientation){},
onDrop : function(row, orientation){},
onToggleOpenState : function(index){},
onCycleHeader : function(column){},
onCycleCell : function(row, column){},
onSelectionChanged : function(){
//dump("selection changed - "+AlbumView.updatedSelection+" - \n");
if (!BookmarksPreviewUtils.utils.updatedSelection)
/*
This listens to the detailed view and the folder view.
Although the selection of the detailed view is updated in time when
this is sent from the detailed view's tree, it isn't updated
in time when it is sent from a selection change from the folder
view so we need to use setTimeout.
*/
setTimeout(function(){
//dump("selection changed - tree observer\n");
BookmarksPreviewUtils.utils.refreshDisplay();
},0);
},
onPerformAction : function(action){},
onPerformActionOnRow : function(action, row){},
onPerformActionOnCell : function(action, row, column){},
_lastTransactionItem : null,
observeTransaction : function(aTxn, aDo){
//dump("observer transaction: "+aTxn+"|"+aDo+"\n");
if (!aTxn) return;
aTxn = aTxn.wrappedJSObject;
//dump("aTxn: "+aTxn+"\n");
var item = aTxn.item;
this._lastTransactionItem = item;
if (this.utils.updatedSelection) return;
var type = aTxn.type;
var itemType = BookmarksUtils.resolveType(item);
if (itemType != "BookmarkSeparator"){
var parent = aTxn.parent;
if (parent == this.displayRoot){
this.utils.refreshDisplay(true);
}
}
},
/* Transaction Listener */
willDo: function (aTxmgr, aTxn) {},
didDo : function (aTxmgr, aTxn) {
this.observeTransaction(aTxn, true);
},
willUndo: function (aTxmgr, aTxn) {},
didUndo : function (aTxmgr, aTxn) {
this.observeTransaction(aTxn, false);
},
willRedo: function (aTxmgr, aTxn) {},
didRedo : function (aTxmgr, aTxn) {
this.observeTransaction(aTxn, true);
},
didMerge : function (aTxmgr, aTxn) {},
didBeginBatch : function (aTxmgr, aTxn) {},
didEndBatch : function (aTxmgr, aTxn) {
this.observeTransaction(aTxn, this.mLastTxnWasDo);
},
willMerge : function (aTxmgr, aTxn) {},
willBeginBatch : function (aTxmgr, aTxn) {},
willEndBatch : function (aTxmgr, aTxn) {},
/* nsIRDFObserver
the transaction manager takes care of everything but when bookmarks
change, so we need the onChange here
*/
onAssert : function(ds, source, predicate, target){},
onUnassert : function(ds, source, predicate, target){},
onChange : function(ds, source, predicate, oldTarget, newTarget){
if (predicate.Value == "http://home.netscape.com/NC-rdf#Name"){
//dump("onChange = source: "+source+" oldTarget: "+oldTarget.Value+" newTarget: "+newTarget.Value+"\n");
var oldVal, newVal;
if (oldTarget instanceof Components.interfaces.nsIRDFLiteral)
oldVal = oldTarget.Value;
if (newTarget instanceof Components.interfaces.nsIRDFLiteral)
newVal = newTarget.Value;
//dump("old|new val: "+oldVal+"|"+newVal+"\n");
this.utils.updateNodeTitle(source,oldVal,newVal);
}
},
onMove : function(ds, oldSource, newSource, predicate, target){},
onBeginUpdateBatch : function(ds){},
onEndUpdateBatch : function(ds){},
/* nsIObserver */
observe: function(subject, topic, data) {
if (topic == "bookmarkpreviews:preview-updated"){
/* subject = updated uri */
this.utils.updatePreview(subject);
}
},
createPreviews : function(){
var strbundleService = Components.classes ["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService);
var bundle = strbundleService.createBundle("chrome://bookmarkpreviews/locale/strings.properties");
var dialogQ = bundle.GetStringFromName("createpreviewsmessage");
var dialogTitle = bundle.GetStringFromName("createpreviewsdialogtitle");
var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var result = prompts.confirm(window, dialogTitle, dialogQ);
if (result){
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var newWindow = wm.getMostRecentWindow("navigator:browser");
if (newWindow)
newWindow.PreviewService.generateAllPreviews();
//XXX do something if there is no preview window...
}
}
}
var AlbumViewUtils = {
all : null,
bkmksTree : null,
tree : null,
view : null,
get bkmksTree(){
return BookmarksPreviewUtils.bkmksTree;
},
get displayRoot(){
return BookmarksPreviewUtils.displayRoot;
},
set displayRoot(val){
BookmarksPreviewUtils.displayRoot = val;
},
initDisplay : function(){
BookmarksPreviewUtils.utils = AlbumViewUtils;
AlbumViewUtils.tree = BookmarksPreviewUtils.bkmksTree.tree;
AlbumViewUtils.view = BookmarksPreviewUtils.bkmksTree.tree.view;
AlbumView.init();
setTimeout(AlbumViewUtils.refreshDisplay,0);
},
uninit : function(){
},
onResize : function(event){
if (AlbumView.canRefresh){
var orient = 1;
if (event.target.id == "bookmark-views-splitter")
orient = 0;//Horizontal
AlbumView.refresh(orient);
/* When dragging the horizontal splitter up the canvas
paints on to the headers of the tree. This will refresh
some of the labels, but it doesn't do the greatest job.
I'm not sure how to force a repaint of an xul element*/
var col = BookmarksPreviewUtils.bkmksTree.treeBoxObject.columns.getFirstColumn().element;
while (col){
col.setAttribute("crop","end");
col.setAttribute("crop","none");
col = col.nextSibling;
}
}
},
refreshDisplay : function(aForceRefresh){
try{
// //dump("refresh album display: "+aForceRefresh+"\n");
var curIndexObj = new Object(), rootIndexObj = new Object();
var previousRoot = AlbumViewUtils.displayRoot;
var root = BookmarksPreviewUtils.getViewRoot(curIndexObj, rootIndexObj);
var curIndex = curIndexObj.value, rootIndex = rootIndexObj.value;
if (aForceRefresh || root!=previousRoot){
var bkmks=[]
BookmarksPreviewUtils.getBookmarkImages(bkmks,root);
AlbumView.createImages(bkmks);
AlbumView.current = AlbumView.target = 0;
}
var nextTarget=AlbumViewUtils._getNextTarget(curIndex,rootIndex);
AlbumView.keepFocus = false;
AlbumView.refresh(-1);
if (!(curIndex>-1 && AlbumViewUtils.view.isSeparator(curIndex)))
AlbumView.glideTo(nextTarget*-150,false);
}catch(e){
Components.utils.reportError("AUTILS: "+e);
}
},
_getNextTarget : function(cIndex,rIndex){
if (cIndex>rIndex+1){
var max = AlbumViewUtils.view.rowCount, level = AlbumViewUtils.view.getLevel(cIndex);
var nextTarget = 0;//rIndex==-1?-1:0;
for (var i = rIndex+1;i<cIndex;i++){
if (AlbumViewUtils.view.getLevel(i)==level &&
!AlbumViewUtils.view.isSeparator(i))
nextTarget++;
}
return nextTarget;
}
return 0;
},
updatePreview : function(aURI){
aURI = aURI.QueryInterface(Components.interfaces.nsIURI);
for (var i = 0; i < AlbumView.max; i++){
var url = AlbumView.itemProps[i].url;
if (url == aURI.spec){
var imgsrc = BookmarksPreviewUtils.getImageForURL(url);
AlbumView.itemImages[i]=null;
AlbumView.itemImages[i]=new Image();
let x = i;
AlbumView.itemImages[i].onload = function preview_load(){
AlbumView.imageLoaded(x);
}
AlbumView.itemImages[i].src = imgsrc;
if (AlbumView.itemImages[i].complete){
AlbumView.imageLoaded(i);
}
break;
}
}
},
updateNodeTitle : function(aNode, aPrevVal, aNewVal){
for (var i = 0; i < AlbumView.max; i++){
var node = AlbumView.itemProps[i].node;
if (node == aNode){
AlbumView.itemProps[i].caption = aNewVal;
AlbumView.caption.value = aNewVal;
break;
}
}
},
selectIndex : function(resource){
if (AlbumView.keepFocus){
AlbumViewUtils.updatedSelection = true;
AlbumViewUtils.view.selection.clearSelection();
AlbumViewUtils.bkmksTree.selectResource(resource);
AlbumViewUtils.bkmksTree.treeBoxObject.ensureRowIsVisible(
AlbumViewUtils.bkmksTree.treeBuilder.getIndexOfResource(resource));
AlbumViewUtils.updatedSelection = false;
//setTimeout(function(){AlbumViewUtils.container.focus();},0);
}
AlbumView.keepFocus = true;
},
performAction : function(resource,event){
//dump("albumviewutils.performaction: "+resource+"|"+event);
var aType = BookmarksUtils.resolveType(resource);
if (aType == "Bookmark"){
var target = BMDS.GetTarget(resource, RDF.GetResource("http://home.netscape.com/NC-rdf#URL"), true);
target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
if (target){
var url = target.Value;
openUILink(url,event);
}
}
else if (aType == "Folder" || aType == "Livemark" || aType == "PersonalToolbarFolder"){
this.updatedSelection = true;
this.bkmksTree.tree.view.selection.clearSelection();
this.updatedSelection = false;
this.bkmksTree.selectResource(resource);
var index = this.bkmksTree.treeBuilder.getIndexOfResource(resource);
if (!this.bkmksTree.tree.view.isContainerOpen(index))
this.bkmksTree.tree.view.toggleOpenState(index);
//AlbumViewUtils.refreshDisplay();
}
}
}
var ThumbViewUtils = {
displayRoot : null,
displayView : null,
view : null,
initDisplay : function(){
ThumbViewUtils.displayView = ThumbView;
BookmarksPreviewUtils.utils = ThumbViewUtils;
document.getElementById('thumbsSize').removeAttribute("disabled");
//ThumbView.init();
this.refreshDisplay(true);
},
uninit : function(){
this.initiated = false;
document.getElementById('thumbsSize').setAttribute("disabled","true");
},
onResize : function(event){
ThumbView.onResize(event);
},
refreshDisplay : function(aForceRefresh){
var bkmks=[];
this.initiated = true;
BookmarksPreviewUtils.getBookmarkImages(bkmks);
ThumbView.load(bkmks);
},
updatePreview : function(aURI){
aURI = aURI.QueryInterface(Components.interfaces.nsIURI);
ThumbView.updateThumbnail(aURI.spec);
},
updateNodeTitle : function(aNode, aPrevVal, aNewVal){
ThumbView.updateNodeTitle(aNode,aPrevVal,aNewVal);
},
back : function(){BookmarksPreviewUtils.back();},
forward : function(){BookmarksPreviewUtils.forward();},
getBookmarkImages : BookmarksPreviewUtils.getBookmarkImages,
_getNextTarget : function(cIndex,rIndex){
if (cIndex>rIndex+1){
var max = ThumbViewUtils.view.rowCount, level = ThumbViewUtils.view.getLevel(cIndex);
var nextTarget = 0;//rIndex==-1?-1:0;
for (var i = rIndex+1;i<cIndex;i++){
if (ThumbViewUtils.view.getLevel(i)==level &&
!ThumbViewUtils.view.isSeparator(i))
nextTarget++;
}
return nextTarget;
}
return 0;
},
selectItem : function(item, event){
//dump("thumbviewutils selectitem: "+item+"\n");
//ThumbViewUtils.updatedSelection = true;
//BookmarksPreviewUtils.bkmksTree.tree.view.selection.clearSelection();
//BookmarksPreviewUtils.bkmksTree.selectResource(item.node);
//ThumbViewUtils.updatedSelection = false;
},
performAction : function(item, event){
//dump("thumbviewutils.performaction\n");
var resource = item.node;
var aType = BookmarksUtils.resolveType(resource);
if (aType == "Bookmark"){
var target = BMDS.GetTarget(resource, RDF.GetResource("http://home.netscape.com/NC-rdf#URL"), true);
target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
if (target){
var url = target.Value;
openUILink(url,event);
}
}
else if (aType == "Folder" || aType == "Livemark" || aType == "PersonalToolbarFolder"){
BookmarksPreviewUtils.bkmksTree.selectResource(resource);
}
},
removeItem : function(item, event){
var resource = item.node;
var parent = BMDS.getParent(resource);
var selection = BookmarksUtils.getSelectionFromResource(resource, parent);
BookmarksCommand.deleteBookmark(selection);
//dump("remove item refresh display\n");
ThumbViewUtils.refreshDisplay();
},
isSorted : function(){
return BookmarksPreviewUtils.sortChangedObserver.isSorted;
}
}
window.addEventListener('load',BookmarksPreviewUtils.init,false);
window.addEventListener('unload',BookmarksPreviewUtils.uninit,false);